import { getCategoryAPI } from '@/apis/category.js'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
let route=useRoute()
import { onBeforeRouteUpdate } from 'vue-router'

export function useCategory()
{
  let categoryData = ref({})
  let route = useRoute()
  const getCategory = async (id=route.params.id) => {
    const res = await getCategoryAPI(id)
    categoryData.value = res.result
  }
  onMounted(() => {
    getCategory()
  })
  onBeforeRouteUpdate(to => {
    console.log('路由变化了')
    getCategory(to.params.id)
  })

  return {
    categoryData
  }
}